<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<!-- 引入vue.js -->
		<script src="./js/vue.js"></script>
	</head>
	<body>
		<div id="app">
			<button @click="onUp">上</button>
			<button @click="onDown">下</button>
			<button @click="onLeft">左</button>
			<button @click="onRight">右</button>

			<div style="position: fixed;width: 100px;
			height: 100px;background-color: bisque;" :style="styleObject">
			</div>
		</div>

		<script type="text/javascript">
			var vm = new Vue({
				el: "#app",
				data: {
					styleObjectNumber: {
						top: 200,
						left: 200,
					}
				},
				methods: {
					onUp() {
						this.styleObjectNumber.top -=20;
					},
					onDown() {
						this.styleObjectNumber.top +=20;					
					},
					onLeft() {
						this.styleObjectNumber.left -=20;						
					},
					onRight() {
						this.styleObjectNumber.left +=20;
					}
				},
				computed: {
					styleObject() {
						return {
							top: this.styleObjectNumber.top + "px",
							left: this.styleObjectNumber.left + "px"
						}
					}

				}
			})
		</script>
	</body>
</html>
